package com.heiyu.task;

import com.heiyu.dao.ArticleInfoMapper;
import com.heiyu.entity.ArticleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

@Component
public class ArticleFilterJob {

    @Autowired
    private ArticleInfoMapper articleInfoMapper;

    @Scheduled(fixedDelay = 300000)
    public void excute(){
        List<Map<String,Object>> list = articleInfoMapper.articleFilter();
        if(!CollectionUtils.isEmpty(list)){
            List<ArticleInfo> filterList;
            for(Map<String,Object> map : list){
                if(map.get("md5")==null){
                    continue;
                }
                 filterList = this.articleInfoMapper.selectBymd5(map.get("md5").toString());
                if(filterList != null && filterList.size()>1){
                    for(int i=1;i<filterList.size();i++){
                        filterList.get(i).setRank(49);
                        this.articleInfoMapper.updateById(filterList.get(i));
                    }
                }
            }
        }
    }
}
